﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KnowledgeAssistant
{
    public partial class EditGroupNumberForm : Form
    {

        public enum ActionType { add, edit}

        private ActionType action_type;
        private Group group;

        public EditGroupNumberForm(ActionType action_type)
        {
            InitializeComponent();
            this.action_type = action_type;
            InitControlNames();
        }

        public EditGroupNumberForm(Group group, ActionType action_type)
        {
            InitializeComponent();
            this.action_type = action_type;
            this.group = group;
            this.groupnumber.Text = this.group.GroupNumber;
            this.group_name_tb.Text = this.group.GroupName;
            InitControlNames();
        }

        private void InitControlNames()
        {
            if (this.action_type == ActionType.add)
            {
                this.Text = "Добавить новую группу";
                this.button1.Text = "Добавить";
            }
            else if (this.action_type == ActionType.edit)
            {
                this.Text = "Изменить номер группы";
                this.button1.Text = "Применить";
            }
        }

        private void EditGroupForm_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string group_number = this.groupnumber.Text.Trim();
            string group_name = this.group_name_tb.Text.Trim();
            if (this.action_type == ActionType.add)
            {
                Group g = new Group(0, group_name, group_number, 0);
                GroupUtil.AddGroupNumber(g);
            }
            else if (this.action_type == ActionType.edit)
            {
                GroupUtil.EditGroupNumber(this.group, group_number, group_name);
            }
            this.Close();
        }
    }
}
